package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;


import Model.Account;
import Model.Accounts;
import View.PanelAddAccount;

public class AddAccount implements ActionListener {

	private PanelAddAccount PAAfrom;
	public String accountNumber;
	public int Gebruiker_ID; 
	public String type;
	public String name;
	public Double interests;
	public Double balance;

	// private int rentePeriode;

	public AddAccount(PanelAddAccount PAAform) {
		this.PAAfrom = PAAform;
	}

	public void actionPerformed(ActionEvent e) {

		if (e.getActionCommand().equals("Toevoegen")) {
			try {
				accountNumber = PAAfrom.getAccountField().getText();
				if (accountNumber.equals("")) {
					JOptionPane.showMessageDialog(null, "U moet een rekening nummer invullen.");
					}
				if (!(accountNumber.equals(""))) {
					type = PAAfrom.getAccountTypeField().getText();
						if (type.equals("")) {
							JOptionPane.showMessageDialog(null,	"U moet een rekening type invullen.");
							}
						if (!(type.equals(""))) {
							name = PAAfrom.getAccountNameField().getText();	
							if (name.equals("")) {
								JOptionPane.showMessageDialog(null,	"U moet een Naam toevoegen aan uw rekening.");
								}
							if (!(name.equals(""))) {
								interests = Double.parseDouble(PAAfrom.getAccountRentField().getText());
									if (interests.equals("")) {
										JOptionPane.showMessageDialog(null,
										"U moet een rente percentage invullen.");
							}
							if (!(interests.equals(""))) {
								balance = Double.parseDouble(PAAfrom.getAccountAmountField().getText());


								if (balance.equals("")) {
									JOptionPane
											.showMessageDialog(null,
													"U moet een saldo invullen.");
								} 
								Account r = new Account(accountNumber, type, name, interests, balance);
		
								Accounts.getInstance().addAccount(r);
								
								System.out.println(r);
//								System.out.println(r.accountNumber+ r.type+ r.accountName+ r.interests+ r.balance);

							}
						}
					}
					
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}

	}

}
